package com.postek.coyote.postekwifi;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.Spinner;
import android.widget.Toast;

import com.postek.cdf.CDFPTKAndroid;
import com.postek.coyote.postekwifi.bean.BBean;
import com.postek.coyote.postekwifi.bean.DMBean;
import com.postek.coyote.postekwifi.bean.HXBean;
import com.postek.coyote.postekwifi.bean.LEBean;
import com.postek.coyote.postekwifi.bean.LOBean;
import com.postek.coyote.postekwifi.bean.LSBean;
import com.postek.coyote.postekwifi.bean.LWBean;
import com.postek.coyote.postekwifi.bean.LabelBean;
import com.postek.coyote.postekwifi.bean.MXBean;
import com.postek.coyote.postekwifi.bean.MessageBean;
import com.postek.coyote.postekwifi.bean.PDFBean;
import com.postek.coyote.postekwifi.bean.QRBean;
import com.postek.coyote.postekwifi.bean.TBean;
import com.postek.coyote.postekwifi.bean.XBean;

import java.util.ArrayList;

/**
 * @author yrwang
 * 
 */
public class MessageActivity extends AppCompatActivity implements OnClickListener {

	private CDFPTKAndroid cdf = MainActivity.cdf;
			
	private Button btn_Set = null;
	private Button btnPrint = null;
	private  Button home=null;
	private Spinner sp_Type = null;

	public static MessageBean messageBean = MainActivity.messageBean;
	public static ArrayList<LabelBean> labelBeans = MainActivity.labelBeans;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.message);

		btn_Set = (Button) findViewById(R.id.btn_print_set);
		btnPrint = (Button) findViewById(R.id.btn_print_print);
		home= (Button) findViewById(R.id.home);
		sp_Type = (Spinner) findViewById(R.id.sp_print_type);
		
		btnPrint.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				//cdf.PTK_PrintLabel(1, 1);
				printLastLabel();

			}
		});


			home.setOnClickListener(this);
		btn_Set.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				int spPision = sp_Type.getSelectedItemPosition();


				Intent intent = new Intent();
				String Order = "";
				switch (spPision) {
				case 0:
					intent.setClass(MessageActivity.this, PrintTActivity.class);
					MessageActivity.this.startActivity(intent);
					break;
				case 1:
					intent.setClass(MessageActivity.this, PrintBActivity.class);
					MessageActivity.this.startActivity(intent);
					break;
				case 2:
					intent.setClass(MessageActivity.this, PrintQRActivity.class);
					MessageActivity.this.startActivity(intent);
					break;
				case 3:
					intent.setClass(MessageActivity.this, PrintHXActivity.class);
					MessageActivity.this.startActivity(intent);
					break;
				case 4:
					intent.setClass(MessageActivity.this, PrintPDFActivity.class);
					MessageActivity.this.startActivity(intent);
					break;
				case 5:
					intent.setClass(MessageActivity.this, PrintMXActivity.class);
					MessageActivity.this.startActivity(intent);
					break;
				case 6:
					intent.setClass(MessageActivity.this, PrintDMActivity.class);
					MessageActivity.this.startActivity(intent);
					break;
				case 7:
					Order = "X";
					intent.setClass(MessageActivity.this, PrintX_LSActivity.class);
					intent.putExtra("Order", Order);
					MessageActivity.this.startActivity(intent);
					break;
				case 8:
					Order = "LE";
					intent.setClass(MessageActivity.this, PrintLE_LO_LWActivity.class);
					intent.putExtra("Order", Order);
					MessageActivity.this.startActivity(intent);
					break;
				case 9:
					Order = "LO";
					intent.setClass(MessageActivity.this, PrintLE_LO_LWActivity.class);
					intent.putExtra("Order", Order);
					MessageActivity.this.startActivity(intent);
					break;
				case 10:
					Order = "LS";
					intent.setClass(MessageActivity.this, PrintX_LSActivity.class);
					intent.putExtra("Order", Order);
					MessageActivity.this.startActivity(intent);
					break;
				case 11:
					Order = "LW";
					intent.setClass(MessageActivity.this, PrintLE_LO_LWActivity.class);
					intent.putExtra("Order", Order);
					MessageActivity.this.startActivity(intent);
					break;
				case 12:
					intent.setClass(MessageActivity.this, RFIDWriteActivity.class);
					startActivity(intent);
					break;
				case 13:
					intent.setClass(MessageActivity.this, RFIDLockActivity.class);
					startActivity(intent);
					break;
				case  14:
						intent.setClass(MessageActivity.this,printPhoto.class);
						MessageActivity.this.startActivity(intent);
						break;
				default:
					break;
				}
			}
		});
		
	}



	public void printLastLabel(){
		if (labelBeans.size() == 0) {
			Toast.makeText(this,   R.string.no_context, Toast.LENGTH_SHORT).show();
		} else {
			cdf.PTK_ClearBuffer();
			cdf.PTK_SetPrintSpeed(messageBean.getiS());
			cdf.PTK_SetDarkness(messageBean.getiH());
			cdf.PTK_SetDirection(messageBean.getiZ());
			cdf.PTK_SetLabelWidth(messageBean.getiq());
			cdf.PTK_SetLabelHeight(messageBean.getiQ1(),
					messageBean.getiQ2(), messageBean.getiQ3(),
					messageBean.getiQ4());

			LabelBean labelBean = new LabelBean();

			for (int i = 0; i < labelBeans.size(); i++) {
				labelBean = labelBeans.get(i);
				if (labelBean.getType().equals("T")) {
					TBean bean = (TBean) labelBean;
					cdf.PTK_DrawText(bean.getiT1(), bean.getiT2(),
							bean.getiT3(), bean.getiT4(), bean.getiT5(),
							bean.getiT6(), bean.getiT7(), bean.getiTS());
				} else if (labelBean.getType().equals("B")) {
					BBean bean = (BBean) labelBean;
					cdf.PTK_DrawBarcode(bean.getiB1(), bean.getiB2(),
							bean.getiB3(), bean.getiB4(), bean.getiB5(),
							bean.getiB6(), bean.getiB7(), bean.getiB8(),
							bean.getiBS());
				} else if (labelBean.getType().equals("DM")) {
					DMBean bean = (DMBean) labelBean;
					cdf.PTK_DrawBar2D_DATAMATRIX(bean.getiDM1(),
							bean.getiDM2(), bean.getiDM3(), bean.getiDM4(),
							bean.getiDM5(), bean.getiDM6(), bean.getiDMS());
				} else if (labelBean.getType().equals("HX")) {
					HXBean bean = (HXBean) labelBean;
					cdf.PTK_DrawBar2D_HANXIN(bean.getiHX1(),
							bean.getiHX2(), bean.getiHX3(), bean.getiHX4(),
							bean.getiHX5(), bean.getiHX6(), bean.getiHX7(),
							bean.getiHX8(), bean.getiHX9(), bean.getiHXS());
				} else if (labelBean.getType().equals("MX")) {
					MXBean bean = (MXBean) labelBean;
					cdf.PTK_DrawBar2D_MaxiCode(bean.getiMX1(),
							bean.getiMX2(), bean.getiMX3(), bean.getiMX4(),
							bean.getiMXS());
				} else if (labelBean.getType().equals("PDF")) {
					PDFBean bean = (PDFBean) labelBean;
					cdf.PTK_DrawBar2D_Pdf417(bean.getiPDF1(),
							bean.getiPDF2(), 0, 0, bean.getiPDF3(),
							bean.getiPDF4(), bean.getiPDF5(),
							bean.getiPDF6(), bean.getiPDF7(),
							bean.getiPDF8(), bean.getiPDF9(),
							bean.getiPDF10(), bean.getiPDFS());
				} else if (labelBean.getType().equals("QR")) {
					QRBean bean = (QRBean) labelBean;
					cdf.PTK_DrawBar2D_QR(bean.getiQR1(), bean.getiQR2(),
							bean.getiQR3(), bean.getiQR4(), bean.getiQR5(),
							bean.getiQR6(), bean.getiQR7(), bean.getiQR8(),
							bean.getiQR9(), bean.getiQRS());
				} else if (labelBean.getType().equals("LE")) {
					LEBean bean = (LEBean) labelBean;
					cdf.PTK_DrawLineXor(bean.getiLE1(), bean.getiLE2(),
							bean.getiLE3(), bean.getiLE4());
				} else if (labelBean.getType().equals("LE")) {
					LOBean bean = (LOBean) labelBean;
					cdf.PTK_DrawLineOr(bean.getiLO1(), bean.getiLO2(),
							bean.getiLO3(), bean.getiLO4());
				} else if (labelBean.getType().equals("LW")) {
					LWBean bean = (LWBean) labelBean;
					cdf.PTK_DrawWhiteLine(bean.getiLW1(), bean.getiLW2(),
							bean.getiLW3(), bean.getiLW4());
				} else if (labelBean.getType().equals("LS")) {
					LSBean bean = (LSBean) labelBean;
					cdf.PTK_DrawDiagonal(bean.getiLS1(), bean.getiLS2(),
							bean.getiLS3(), bean.getiLS4(), bean.getiLS5());
				} else if (labelBean.getType().equals("X")) {
					XBean bean = (XBean) labelBean;
					cdf.PTK_DrawRectangle(bean.getiX1(), bean.getiX2(),
							bean.getiX3(), bean.getiX4(), bean.getiX5());
				}
			}

			cdf.PTK_PrintLabel(1, 1);
		}
	}

	@Override
	public void onClick(View v) {
		//startActivity(new Intent(MessageActivity.this,MainActivity.class));
		finish();
	}
}
